package cn.liziguo.tank.collision;

import cn.liziguo.tank.constants.GameEnum;
import cn.liziguo.tank.script.BaseTankComponent;
import cn.liziguo.tank.script.BulletComponent;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.physics.CollisionHandler;

/**
 * @author Liziguo
 * @date 2022-07-09 21:26:11
 */
public class BulletEnemyCollisionHandler extends CollisionHandler {

    public BulletEnemyCollisionHandler() {
        super(GameEnum.BULLET, GameEnum.ENEMY);
    }

    @Override
    protected void onCollisionBegin(Entity bullet, Entity b) {
        if (BaseTankComponent.getTankComponent(b).isInvincible()) {
            return;
        }
        BulletComponent bulletComponent = bullet.getComponent(BulletComponent.class);
        BaseTankComponent.getTankComponent(b).underAttack(bulletComponent.attack);

        BulletComponent.onRemove(bullet);
    }
}
